//
//  AXMySrdzWdzwVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/7.
//  Copyright © 2018 tzhg. All rights reserved.
//我的作物列表

#import "AXMySrdzWdzwVC.h"
#import "ZXCategories.h"
#import "UIView+SDAutoLayout.h"
#import "AXMySrdzWdzwCell.h"
#import "AXMySrdzWdzwModel.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "AXMySrdzWdzwZwjdVC.h"
#import "AXMyCropManageVC.h"

@interface AXMySrdzWdzwVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) NSMutableArray<AXMySrdzWdzwModel *> *modelsArray;

@property (nonatomic , strong) UITableView *tableView;


@end

@implementation AXMySrdzWdzwVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavigationItems];
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self creatView];
    [self setlayout];
    
    
}

- (void)creatView {
    
    self.tableView = [[UITableView alloc]init];
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[AXMySrdzWdzwCell class] forCellReuseIdentifier:[AXMySrdzWdzwCell reuseID]];
    [self.view addSubview:self.tableView];
}

- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, Hn)
    .widthIs(SCREEN_WIDTH)
    .heightIs(TableViewHeight);
    

    
}


- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    
    //返回按钮
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.titleLabel.font = FONT_FOURTEEN;
    [rightBtn setTitleColor:COLOR_ORG forState:UIControlStateNormal];
    [rightBtn setTitle:@"新增" forState:UIControlStateNormal];
    [rightBtn setImage:[UIImage imageNamed:@"zwadd"] forState:UIControlStateNormal];
    rightBtn.frame = CGRectMake(0, 0, 30, 30);
    [rightBtn addTarget:self action:@selector(addAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    
    /** 搜索 */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"我的作物";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)addAction:(UIBarButtonItem *)item {
    
    AXMySrdzWdzwZwjdVC *vc = [[AXMySrdzWdzwZwjdVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
}



#pragma mark - tableViewDelegate & tableViewDatasorce



//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

/** cell的高度 */

/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray[indexPath.row] keyPath:@"model" cellClass:[AXMySrdzWdzwCell class] contentViewWidth:SCREEN_WIDTH];
    
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    AXMySrdzWdzwCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMySrdzWdzwCell reuseID] forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
    //管理按钮的事件
    cell.tapButtonClickedBlock = ^(NSInteger index) {
        
        AXMyCropManageVC *vc = [[AXMyCropManageVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        
    };
    
    
    return cell;
    
    
}




@end





